
local skill = fk.CreateSkill {
  name = "lvshi__liangzhu",
  tags = {"Turn"}
}

Fk:loadTranslationTable{
  ["lvshi__liangzhu"] = "良助",
  [":lvshi__liangzhu"] = "回合技，当你于摸牌阶段外一次获得两张牌后，或于弃牌阶段外一次失去两张牌后，你可选择一名其他角色，你和其体力值较小的角色回复1点体力，然后未回复体力的角色摸一张牌。",
  ["#lvshi__liangzhu-choose"] = "良助：你可选择一名其他角色",

  ["$lvshi__liangzhu1"] = "蔷薇不需要谁的保护，她们自己就是武器！",
  ["$lvshi__liangzhu2"] = "这里的花，只为真诚绽放。",
}

skill:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skill.name) and player:usedSkillTimes(skill.name) == 0 then
      for _, move in ipairs(data) do
        if move.from == player and player.phase ~= Player.Discard then
          local cards = {}
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(cards, info.cardId)
            end
          end
          return #cards >= 2
        elseif move.to == player and player.phase ~= Player.Draw then
          return move.toArea == Card.PlayerHand and #move.moveInfo >= 2
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = skill.name,
      prompt = "#lvshi__liangzhu-choose",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local players = {player, to}
    local recover = nil
    if player.hp < to.hp and player:isWounded() then
      recover = player
    elseif player.hp > to.hp and to:isWounded() then
      recover = to
    end
    if recover then
      table.removeOne(players, recover)
      room:recover({
        who = recover,
        num = 1,
        recoverBy = player,
        skillName = skill.name
      })
    end
    for _, p in ipairs(players) do
      if p:isAlive() then
        p:drawCards(1, skill.name)
      end
    end
  end,
})


return skill